import * as three from 'three'

class Model {
  createEarth () {
    const that = this
    // 添加地球
    var geometry = new THREE.SphereGeometry(100, 32, 32)
    // var texture = new THREE.TextureLoader()
    //   .setPath('static/model/img/')
    //   .load('earth.jpg')
    // texture.minFilter = THREE.LinearFilter
    // var material = new THREE.MeshPhongMaterial({
    //   map: texture
    // })
    var textureLoader = new THREE.TextureLoader().setPath('static/model/img/earth/')
    var material = new THREE.MeshPhongMaterial({
      specular: 0x333333,
      shininess: 15,
      map: textureLoader.load('earth_atmos_2048.jpg'),
      specularMap: textureLoader.load('earth_specular_2048.jpg'),
      normalMap: textureLoader.load('earth_normal_2048.jpg'),
      // y scale is negated to compensate for normal map handedness.
      normalScale: new THREE.Vector2(0.85, -0.85)
    })
    that.globeMesh = new THREE.Mesh(geometry, material)
    that.globeMesh.name = 'earth'
    that.globeMesh.position.set(0, 0, 0)
    that.scene2.add(that.globeMesh)

    // 地球 雾
    var materialClouds = new THREE.MeshLambertMaterial({
      map: textureLoader.load('earth_clouds_1024.png'),
      transparent: true
    })

    that.meshClouds = new THREE.Mesh(geometry, materialClouds)
    that.meshClouds.scale.set(1.005, 1.005, 1.005)
    that.meshClouds.position.set(0, 0, 0)
    that.meshClouds.name = 'earth'
    that.scene2.add(that.meshClouds)
  }

  createMoon () {
    const that = this
    // 月球
    var materialMoon = new THREE.MeshPhongMaterial({
      map: textureLoader.load('moon_1024.jpg')
    })

    that.meshMoon = new THREE.Mesh(geometry, materialMoon)
    that.meshMoon.position.set(500, 0, 0)
    that.meshMoon.scale.set(0.23, 0.23, 0.23)
    that.meshMoon.name = 'moon'
    that.scene2.add(that.meshMoon)
  }
}
